package mongo

import (
	"gitee.com/lstack_light/light-utils/middleware/sql/common"
	"gorm.io/gorm"
	"os"
	"time"
)

type DbConfig struct {
	Driver          string
	Url             string
	ConnMaxLifetime time.Duration
	MaxOpenConns    int
	MaxIdleConns    int
	LogMode         bool
	// LogType Type of the log to be printed
	// os.Stdin || os.Stdout || os.Stderr
	LogType *os.File
}

type client struct {
	Db *gorm.DB
}

type native struct {
	client
}

// CreateMongoCustomClient
/*

@author KangXu

@description Example Initialize the native mongo client

@return Returns a native mongo client pointer object
*/
func (s *client) createMongoCustomClient() *native {
	return &native{client{s.Db}}
}

type Native interface {
	GetType() common.DbType
}

func (n *native) GetType() common.DbType {
	return common.Mongo
}

// NewMongoClient
/*

@author KangXu

@description Initialize a mongo client

@param dbConfig is used to initialize the mongo database

@return Return the pointer object of the mongo client and the pointer object of the native concatenation client and the error information generated during the process
*/
func NewMongoClient(dbConfig *DbConfig) (*client, *native, error) {
	s := client{Db: nil}
	return &s, s.createMongoCustomClient(), nil
}
